/**
 * 医疗服务质询初始化模块，提供医疗服务编辑页面初始化组件功能
 * 
 * @Date: 2016-1-25
 * @author: Jackson wang
 * @version: 1.0
 * @since: 1.0
 */

define(["jquery","sysmanMain","valueUtil"],
		function($,sysmanMain,valueUtil) {
			
		'use strict';
		
		var public_method ={
			
			/**
			 * 获取高级查询字段内容
			 * @param _options.rootId
			 */
			getConditionValue:function(_options){
				var _rootpath = '/'+sysmanMain.getRootPath()
				var ret = {}
				if(_options.rootId && _options.form){
					var $form = $('#' + _options.rootId + ' ' + _options.form)
					if($form.length>0){
						var boxElement=['doct_depart_name','doct_name','patient_id']
						for(var i=0;i<boxElement.length;i++){
							var _tmpValue = private_method.getTextboxValue($form,boxElement[i])
							if(_tmpValue){
								ret = $.extend(ret,_tmpValue)
							}
						}
					}
					
					var $condition = $('#' + _options.rootId + ' ' +" div.tb-list")
					if($condition.length>0){
							
						var _timeValue=	valueUtil.getStartEndDate({
								fieldName:'inhzospitalat',
								startEl:$condition.find('#inhzospitalat_start'),
								endEl:$condition.find('#inhzospitalat_end')
							})
						if(_timeValue!=null && !$.isEmptyObject(_timeValue)){
							ret=$.extend(ret,_timeValue)
						}
					}
				}
				return ret
			},
			
			
			rowClick:function(index,data){
				
				if(window.console)
					console.info('inpatient rowClick event fired ...')
				var _config = sysmanMain.getModuConf('inpatientItemFee');
				if(_config ==null){
					_config = {}					
				}	
				
				_config.initQueryParams = {field:'patient_id',fieldVal:data.patient_id}
				sysmanMain.setModuConf('inpatientItemFee',_config)
				sysmanMain.medicalInpatientItemFeeSelect()
			},
			/**
			 * 初始化新增页面
			 * @param _options.record 列表选中行
			 * @param _options.form 页面form对象
			 * @param _options.rootId 页面根节点
			 */
			initElement:function(_options){
				var _rootpath = '/'+sysmanMain.getRootPath()
				
				var deptQueryUrl='/department/query/getTreeList.action'
				//判断form对象是否存在
				if(_options){
					if(_options.rootId){
						var _startDate = $('#' + _options.rootId + ' #inhzospitalat_start')
						
						var _endDate = $('#' + _options.rootId + ' #inhzospitalat_end')
						if(_startDate.length>0){
							var curDate = new Date();
							
							var _tmp = valueUtil.getDateValue({source:curDate,format:'yyyy-MM-dd'})
							$(_endDate).datebox('setValue',_tmp);							
							
							
							curDate.setDate(1);
							
							_tmp = valueUtil.getDateValue({source:curDate,format:'yyyy-MM-dd'})
							$(_startDate).datebox('setValue',_tmp);
						}
					}

					
				}
			}
			
		}
		
		var private_method ={
			
			/**
			 * 获取textbox值
			 */
			getTextboxValue:function(formElement,fieldName){
				var ret = {}
				if(formElement.length>0){
					if(fieldName){
						var _tmpEl = $(formElement).find('#'+fieldName)
						if(_tmpEl && _tmpEl.length>0){
							var _tmpValue = $(formElement).find('#'+fieldName).textbox('getText')
							if(_tmpValue){
								_tmpValue = $.trim(_tmpValue)
								if(_tmpValue !=''){
									ret[fieldName]=_tmpValue
	//								ret[fieldName]=encodeURI(_tmpValue)
								}						
							}
						}
					}
				}
				return ret
			}
		}
			
		
		return public_method;
			
})